﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain;
using IntelligentAgriculture.Domain.Enum;
using IntelligentAgriculture.WebAPI.Application.Command.DepartMentCommand;
using IntelligentAgriculture.WebAPI.Application.Command.SheepCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IntelligentAgriculture.WebAPI.Controllers
{

    /// <summary>
    /// 部门设置
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartMentController : ControllerBase
    {


        private readonly IDepartMentService departService;
        private readonly TokenService tokenService;
        private readonly ILogger<DepartMentController> logger;
        private readonly IMediator mediator;


        /// <summary>
        /// 注入
        /// </summary>
        /// <param name="departService"></param>
        /// <param name="tokenService"></param>
        /// <param name="logger"></param>
        /// <param name="mediator"></param>
        public DepartMentController(IDepartMentService departService
            , TokenService tokenService
            , ILogger<DepartMentController> logger, IMediator mediator)
        {
            this.departService = departService;
            this.tokenService = tokenService;
            this.logger = logger;
            this.mediator = mediator;

        }

        /// <summary>
        /// 部门查询分页
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<PageOutput<DepartMentOutPut>>> DepartMnetList(DepartMentInPut input)
        {
            var command = new DepartMentQueryCommand(input);
            var roles = await mediator.Send(command);
            return roles;
        }


        /// <summary>
        /// 部门添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddDepart(DepartMentCreateCommand command)
        {
            return await mediator.Send(command);
        }


        /// <summary>
        /// 部门导出
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ExportDepartMent([FromQuery] DepartMentInPut? input)
        {
                var command = new DepartMentExportCommand(input);
                var result = await mediator.Send(command);
                return result;
        }

    /// <summary>
    /// 树形列表
    /// </summary>
    /// <param name="pid"></param>
    /// <returns></returns>
        [HttpGet]
        public async Task<Results<List<MenuList>>> MenuList(int pid)
        {
            var command = new DepartMentMenuCommand(pid);
            var roles = await mediator.Send(command);
            return roles;
        }



      
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="departId"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<Results<int>> DeleteDepart(int departId)
        {
            var command = new DepartMentDeleteCommand(departId);
            return await mediator.Send(command);
        }




        /// <summary>
        /// 枚举列表
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        public IActionResult GetDepartMent()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<DepartMentType>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item
                });

            }
            return Ok(list);

        }





    }




}
